package cn.itcast.consumer.client;

import cn.itcast.consumer.config.FeignConfig;
import cn.itcast.consumer.pojo.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author 虎哥
 */
@FeignClient(value = "user-service",
        fallback = UserClient.UserClientFallback.class,
        configuration = FeignConfig.class)
public interface UserClient {

    @GetMapping("/user/{id}")
    User queryById(@PathVariable("id") Long id);

    /**
     * 这个实现类，就是UserClient接口的 fallback类，编写失败降级逻辑
     */
    @Component
    class UserClientFallback implements UserClient{

        @Override
        public User queryById(Long id) {
            return new User();
        }
    }
}
